class Solution:
    def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
        nums1.sort()
        nums2.sort()
        key1, key2 = 0, 0
        ans = []
        while key1 < len(nums1) and key2 < len(nums2):
            if nums1[key1] == nums2[key2]:
                ans.append(nums1[key1])
                key1 += 1
                key2 += 1
            elif nums1[key1] > nums2[key2]:
                key2 += 1
            else:
                key1 += 1
        return ans